<?php
require_once dirname(dirname(dirname(dirname(__FILE__)))) . "/config/global_config.php";


/**
 *创建表格布局，并填入响应的数据
 * 
 * @param int $row  行的数量
 * @param array $header 表头信息
 * @param array $data 数据
 * @return array
 */
function createTable($row, $header = array(), $data = array())
{
    $table = "<table border='1' cellspacing='0'  width='1400' height='100' align='center' id='table-cont'>";
    if ($header != NULL) {
        $b = count($header);
    }
    for ($i = 1; $i <= $row; $i++) { //行
        if ($i == 1) {
            $table .= "<thead>";
            $table .= "<tr align='center'>";
            for ($j = 0; $j < $b; $j++) { //列
                $table .= "<th>" . $header[$j] . "</th>"; //表头
            }
            $table .= "</tr>";
            $table .= "</thead>";
            $table .= "<tbody>";
        } else {
            $table .= "<tr align='center'>";
            for ($j = 0; $j < $b; $j++) { //列
                //$table .= "<td>" . $data[$i - 1][$header[$j]] . "</td>"; //每行数据
                if ((!empty($data[$i - 1][$header[$j]])) || ($data[$i - 1][$header[$j]] == "0")) {
                    $table .= "<td>" . $data[$i - 1][$header[$j]] . "</td>"; //每行数据
                } else {
                    $table .= "<td>" . "NULL" . "</td>"; //每行数据
                }
            }
            $table .= "</tr>";
        }
    }
    $table .= "</tbody>";
    $table .= "</table>";
    echo $table;
}

function filterForTime($row, $time, $data = array())
{
    $newdata = array();
    $index = 1;
    for ($i = 0; $i <= $row; $i++) {
        if (!empty($data[$i])) {
            if (
                strtotime($data[$i][COLUMN_Time]) >= strtotime($time[SMALLTIME]) &&
                strtotime($data[$i][COLUMN_Time]) <= strtotime($time[BIGTIME])
            ) {
                $newdata[$index] = $data[$i];
                $index++;
            }
        }
    }
    return $newdata;
}

function checkData($row, $header = array(), $data = array())
{
    if ($header != NULL) {
        $b = count($header);
    }
    for ($i = 1; $i <= $row; $i++) { //行
        for ($j = 0; $j < $b; $j++) { //列
            if ($data[$i][$header[$j]] == "") {
            }
        }
    }
}
